from xlrd import open_workbook
import allure
from xlutils.copy import copy

#读取文件数据
@allure.step("读取文件数据")
def excel():

    table = open_workbook(r'src/excel/res.xls', formatting_info=True)
    sheet = table.sheet_by_index(0) #获取sheet
    keys = sheet.row_values(0) #第一行作为key

    data = []
    #便利
    for row in range(1,sheet.nrows):
        data.append(dict(zip(keys ,sheet.row_values(row))))
    print("data:",data)
    return data

#保存文件
def saveExcel(file):
    f = file.read();
    fileCopy = open_workbook(file_contents=f)
    newWorkBook = copy(fileCopy)
    newWorkBook.save(r'src/excel/res.xls')
